home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: MegaDisc / MegaDisc 41 (1994-09)(MegaDisc Digital Publishing)(AU)(Disk 2 of 2).zip / MegaDisc 41 (1994-09)(MegaDisc Digital Publishing)(AU)(Disk 2 of 2).adf / Programming / C_Tute / program4.c < prev    next >
C/C++ Source or Header  |  1994-07-27  |  1KB  |  49 lines

  1.  
  2.  
  3. /***********************************************************************
  4. * Examples of how to use strings with C.
  5. ***********************************************************************/
  6.  
  7. main()
  8. {
  9. char string1[100],string2[100]; /* 2 string variables. Each can hold 99
  10.                                    characters. */
  11.  
  12. /*********************/
  13. /* example of strcpy */
  14. /*********************/
  15. strcpy(string1,"simon"); /* OK! */
  16.  
  17. strcpy(string1,string2); /* OK! */
  18.  
  19. /* strcpy("simon",string1); ILLEGAL!! */
  20.  
  21. /* strcpy(string1,'J'); ILLEGAL!! You can't copy a character into a string */
  22.  
  23.  
  24. /*********************/
  25. /* example of strcat */
  26. /*********************/
  27. strcat(string1,string2); /* attach string2 to string 1 */
  28.  
  29. strcat(string1,"!!"); /* OK! */
  30.  
  31. /* strcat("!!",string1);  ILLEGAL!! */
  32.  
  33. /* strcat(string1,'J'); ILLEGAL!! You can't attach a character to a string */
  34.  
  35.  
  36. /*********************/
  37. /* example of strcmp */
  38. /*********************/
  39. if( strcmp(string1,string2)==0 )
  40.    {
  41.    printf("Both strings are equal!\n");
  42.    }
  43.    else
  44.    {
  45.    printf("Strings are not equal!\n");
  46.    }
  47.  
  48. }
  49.